import 'package:detect/entity/entity.dart';
import 'package:detect/utils/db_util.dart';
import 'package:flutter/material.dart';

class RadioControlNotifier extends ChangeNotifier {
  Future<int> deleteRadio(int id) async {
    int result = await DBApi.radio.delete(id);
    if ((result) >= 1) notifyListeners();
    return result;
  }

  Future<RadioEntity?> submitRadio(RadioEntity entity) async {
    bool contain = await DBApi.radio.contain(entity.id);
    RadioEntity? result = await (contain ? DBApi.radio.update(entity) : DBApi.radio.insert(entity));
    if (result != null) notifyListeners();
    return result;
  }
}
